package com.lc.qianrenshiye.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.lc.qianrenshiye.BaseActivity;
import com.lc.qianrenshiye.R;
import com.lc.qianrenshiye.adapter.OrderDetailAdapter;
import com.lc.qianrenshiye.adapter.OrderDetailAddAdapter;
import com.lc.qianrenshiye.conn.OrderDetailGet;
import com.lc.qianrenshiye.uitls.MyToast;
import com.lc.qianrenshiye.widget.NoScrollListView;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by shenyuxin on 2016/11/17.
 */
public class OrderDetailActivity extends BaseActivity{

    @BoundView(R.id.my_order_add_lv) private NoScrollListView my_order_add_lv;
    @BoundView(R.id.my_order_lv) private NoScrollListView my_order_lv;
    @BoundView(R.id.my_order_add_rl) private RelativeLayout my_order_add_rl;
    @BoundView(R.id.my_order_title_rl) private RelativeLayout my_order_title_rl;

    private List<OrderDetailGet.Goods> lists = new ArrayList<>();
    private List<OrderDetailGet.Addeds> addLists = new ArrayList<>();

    private OrderDetailAdapter adapter;

    private OrderDetailAddAdapter addAdapter;

    private OrderDetailGet orderDetailGet = new OrderDetailGet(new AsyCallBack<OrderDetailGet.OrderDetailEntity>() {

        @Override
        public void onSuccess(String toast, int type, OrderDetailGet.OrderDetailEntity orderDetailEntity) throws Exception {

            lists.addAll(orderDetailEntity.goodsList);
            adapter.notifyDataSetChanged();

            if (orderDetailEntity.addedsList.size() > 0) {

                addLists.addAll(orderDetailEntity.addedsList);

                addAdapter.notifyDataSetChanged();

                my_order_add_rl.setVisibility(View.VISIBLE);

            }

        }

        @Override
        public void onFail(String toast, int type) throws Exception {


            MyToast.showToast(toast, context);

        }

    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_detail);

        setBackTrue();

        setTitleName(getString(R.string.order_detail_title_text));

        my_order_lv.setAdapter(adapter = new OrderDetailAdapter(context, lists));

        my_order_add_lv.setAdapter(addAdapter = new OrderDetailAddAdapter(context, addLists));


        orderDetailGet.oid = getIntent().getStringExtra("orderId");
        orderDetailGet.execute(this);


    }



}
